home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
235_02
/
ovwin.c
< prev
next >
Wrap
Text File
|
1987-06-16
|
34KB
|
952 lines
/* 034 14-Feb-87 ovwin.c
Copyright (c) 1987 by Blue Sky Software. All rights reserved.
*/
#include <setjmp.h>
#include <dos.h>
#include "ov.h"
#ifndef NULL
#define NULL (0)
#endif
#define V_bar (0xba)
#define H_bar (0xcd)
int diridx = 0; /* # dir names when showall */
char **dirlst = NULL; /* ptr to dir name ptrs when showall */
static int win_update; /* NZ if refresh_screen update */
static unsigned char inwin = 0; /* # active info windows */
static unsigned char numwin = 1; /* # active windows */
static WINDOW *curwin = NULL, *winlis = NULL, *winp;
static char *tdir; /* target dir */
static char *tname; /* target name */
static FILE_ENT holdf; /* save file_ent */
static char *nomem = "Insufficient memory for another window, no window created!";
static char *noaccess = "Unable to access specified directory: ";
extern WINDOW cw;
extern int winupdate;
extern FILE_ENT files[];
extern unsigned dataseg;
extern jmp_buf back_to_main;
extern unsigned char anyshowall;
char far *malloc_f();
int ALTCALL scanwindows(), ALTCALL win_switch();
int addfile_ent(), delfile_ent(), refresh_window();
char *strrchr(), *strchr(), *parsepath(), *findir();
int ALTCALL wincpy(WINDOW *, WINDOW *), ALTCALL disp_empty_msg(int);
int ALTCALL savefiles(char far *, int), ALTCALL restorefiles(char far *, int);
/******************************************************************************
** W I N _ O P E N **
*****************************************************************************/
win_open() { /* open another file name display window */
register WINDOW *wp;
/* make sure the current window is large enough to split */
if (cw.wrows < 6)
show_error(0,10,1,"Current window is too small to open another");
/* allocate memory for the new window structure */
if ((wp = (WINDOW *) malloc(sizeof(WINDOW))) == NULL)
show_error(0,11,1,nomem);
wincpy(wp,&cw); /* initialize new window via current window */
/* allocate memory to store files[] data */
if ((wp->save_files = malloc_f(MAX_FILES * sizeof(FILE_ENT))) == NULL) {
free((char *)wp);
show_error(0,12,1,nomem);
}
/* if there is only one window open so far, create the window structure
and files[] save area to store the current window stuff */
if (numwin == 1) {
curwin = (WINDOW *) malloc(sizeof(WINDOW));
cw.save_files = malloc_f(MAX_FILES * sizeof(FILE_ENT));
if (curwin == NULL || cw.save_files == NULL) {
free((char *)wp);
if (curwin) {
free((char *)curwin);
curwin = NULL;
}
show_error(0,13,1,nomem);
}
cw.prev = cw.next = winlis = curwin;
}
savefiles(cw.save_files,cw.nfiles); /* save current window's files[] data */
/* link the new window just after the current window */
wincpy(curwin,&cw);
wp->next = curwin->next;
wp->prev = curwin;
wp->prev->next = wp;
wp->next->prev = wp;
wincpy(&cw,curwin);
/* adjust the current window and new window display sizes */
wp->wrows = cw.wrows / 2; /* new is at most 1/2 of current */
cw.wrows = cw.wrows - wp->wrows; /* current keeps whats left */
wp->fwrow = cw.fwrow + cw.wrows; /* new start at end of current */
cw.ndrows -= wp->wrows; /* all new rows came from name disp */
wp->fnrow = wp->fwrow + 1; /* one overhead row for dir name */
wp->ndrows = wp->wrows - 1;
/* adjust the top window if it was the only one and it didn't already
have a header line */
if (numwin == 1 && !cw.showall) {
cw.fnrow++; /* need a line to display window */
cw.ndrows--; /* directory line */
insert_line(cw.fwrow+1,cw.wrows-1); /* scroll file info down a line */
disp_dirname(); /* disp the dir name */
}
/* adjust old window if current item is no longer visible and turn off
the file pointer in the old window */
if (!on_screen(cw.curidx)) { /* adjust/redisplay window */
adjust_window(); /* if current item no longer */
update_window(0); /* displayed */
} else /* not redisplaying window, turn off highlighted ptr */
if (cw.nfiles) /* turn off file ptr in old window */
fp_off(cw.curidx);
else /* or de-highlight empty dir msg */
disp_empty_msg(0);
/* make the new window the current one */
wincpy(curwin,&cw); /* save the old current one */
wincpy(&cw,wp); /* new one becomes current */
curwin = wp; /* remember who it is */
numwin++; /* one more window than there was */
if (cw.info_display) /* if info display is active, there */
infocnt(1); /* is now 1 more info window active */
/* only one window can be in showall mode */
if (cw.showall) { /* did the old window have showall? */
cw.showall = 0; /* yes, turn off on this one */
getfiles(); /* reread current dir only */
update_header(); /* display current dir header info */
}
/* display the file data in the new window */
adjust_window();
update_window(1);
}
/******************************************************************************
W I N _ C L O S E
*****************************************************************************/
win_close() { /* close the current window */
int fwrowadj;
register WINDOW *wp;
if (numwin == 1) /* nothing to do if only one window */
return;
/* determine the window adjustment fudge factor, 1 extra line is available
if only one window will remain and that window is not showall */
fwrowadj = (numwin == 2 && (!anyshowall || cw.showall)) ? 0 : 1;
/* adjust the next or prior window to take up the closing windows space
on the screen. Always pick the next window unless current is the
last one displyed */
if ((wp = cw.next) != winlis) { /* next = winlis if last */
wp->fwrow = cw.fwrow; /* adj nxt to take over */
} else /* closing last window on screen */
wp = cw.prev; /* prev is current to be */
wp->wrows += cw.wrows; /* it has this many more rows */
wp->fnrow = wp->fwrow + fwrowadj; /* name display rows */
wp->ndrows = wp->wrows - fwrowadj;
cw.next->prev = cw.prev; /* delink the current (closing) */
cw.prev->next = cw.next; /* windows block from window list */
if (curwin == winlis) /* keep track of new top window if */
winlis = wp; /* old top is being closed */
if (cw.showall) /* turn off showall mode if this */
showoff(); /* window had it on */
if (cw.info_display) /* one less info window if this wind */
infocnt(-1); /* had info display active */
free_f(cw.save_files); /* free the cur win's files[] area */
free((char *)curwin); /* free the cur/old win's block */
/* make the next (or prior) window current, restore its files */
wincpy(&cw,curwin = wp);
restorefiles(cw.save_files,cw.nfiles);
numwin--; /* one less window now */
/* when there is only one window, don't keep the block and files[]
save area overhead */
if (n